package org.apache.dolphinscheduler.api.controller;

import static org.apache.dolphinscheduler.api.enums.Status.QUERY_CORPORATE_REMITTANCE_FAIL;

import org.apache.dolphinscheduler.api.aspect.AccessLogAnnotation;
import org.apache.dolphinscheduler.api.exceptions.ApiException;
import org.apache.dolphinscheduler.api.service.CorporateRemittanceService;
import org.apache.dolphinscheduler.api.utils.Result;
import org.apache.dolphinscheduler.common.constants.Constants;
import org.apache.dolphinscheduler.dao.entity.CorporateRemittance;
import org.apache.dolphinscheduler.dao.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestAttribute;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;

@Tag(name = "CORPORATE_REMITTANCE_TAG")
@RestController
@RequestMapping("/corporate-remittance")
public class CorporateRemittanceController extends BaseController {

	@Autowired
	private CorporateRemittanceService corporateRemittanceService;
	
	@Operation(summary = "queryCorporateRemittance", description = "QUERY_CORPORATE_REMITTANCE_NOTES")
    @GetMapping(value = "/get")
    @ResponseStatus(HttpStatus.OK)
    @ApiException(QUERY_CORPORATE_REMITTANCE_FAIL)
    @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
    public Result<Object> queryCorporateRemittance(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser) {
		return corporateRemittanceService.getCR(loginUser);
    }
	
	@Operation(summary = "saveCorporateRemittance", description = "SAVE_CORPORATE_REMITTANCE_NOTES")
    @PostMapping
    @ResponseStatus(HttpStatus.OK)
    @ApiException(QUERY_CORPORATE_REMITTANCE_FAIL)
    @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
    public Result<Object> saveCorporateRemittance(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestBody CorporateRemittance cr) {
		return corporateRemittanceService.saveCR(loginUser,cr);
    }
}
